package cn.com.thingo.hyintelligent.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bertsir.zbar.QrConfig;
import cn.bertsir.zbar.QrManager;
import cn.com.thingo.hyintelligent.R;
import cn.com.thingo.hyintelligent.app.listener.OnEzBottomPopClickListener;


public class EzBottomPopwindow extends PopupWindow implements View.OnClickListener {
    private Context mContext;
    private View mContentView;
   private OnEzBottomPopClickListener mOnEzBottomPopClickListener;
    public EzBottomPopwindow(Context context) {
        super(context);
        this.mContext = context;
        mContentView = LayoutInflater.from(context).inflate(R.layout.pop_ezadd_menu, null);
        setContentView(mContentView);
        setWidth(mContext.getResources().getDisplayMetrics().widthPixels);
        setHeight(mContext.getResources().getDisplayMetrics().heightPixels);
        setAnimationStyle(R.style.PopAnimBottom);
        setBackgroundDrawable(new ColorDrawable());
        setFocusable(true);
        setOutsideTouchable(true);
        setTouchable(true);
        setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                /**
                 * 判断是不是点击了外部
                 */
                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                    return true;
                }
                //不是点击外部
                return false;
            }
        });
        initView();
    }

    private void initView() {
        PopHolder holder = new PopHolder(mContentView);
        holder.mScanButton.setOnClickListener(this);
        holder.mWriteButton.setOnClickListener(this);
        holder.mCancelButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_ez_pop_scan:
                if (mOnEzBottomPopClickListener!=null){
                   mOnEzBottomPopClickListener.OnEzAddScanClick(v);
                }
                break;
            case R.id.btn_ez_pop_write:
              if (mOnEzBottomPopClickListener!=null){
                  mOnEzBottomPopClickListener.OnEzAddWriteClick(v);
              }
                break;
            case R.id.btn_ez_pop_cancel:
                dismiss();
                break;

        }
    }



    class PopHolder {
        @BindView(R.id.btn_ez_pop_scan)
        Button mScanButton;
        @BindView(R.id.btn_ez_pop_write)
        Button mWriteButton;
        @BindView(R.id.btn_ez_pop_cancel)
        Button mCancelButton;

        public PopHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    public void setOnEzBottomPopClickListener(OnEzBottomPopClickListener onEzBottomPopClickListener){
        mOnEzBottomPopClickListener = onEzBottomPopClickListener;
    }

}
